<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="mvc" uri="http://www.trkj.com/mvc/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<link type="text/css" rel="stylesheet" href="css/lgoodslist.css"/>
<link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" />
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js" ></script>
<script type="text/javascript">
	$(function(){
		//单项删除
		$(".goodslist_delete").click(function(){
			if(confirm("真的要删除吗？")){
				var a = $(this);
				$.get("goodslist?action=delete", {code: a.attr("id")}, function(){
					a.parent().parent().remove();
				});
			}
		});
		//单项还原
		$(".goodslist_restore").click(function(){
			if(confirm("确定还原吗？")){
				var a = $(this);
				$.get("goodslist?action=reviseIfdelete", {code: a.attr("id"),ifdelete: 1}, function(){
					a.parent().parent().remove();
				});
			}
		});
		//全选
		var num=0;
		$(".checkbox").click(function(){
			var all=$("input[name='checkbox']");
			if(num%2==0){
				for(var i=0;i<all.length;i++){
					all[i].checked=true;
				}
			}else{
				for(var i=0;i<all.length;i++){
					all[i].checked=false;
				}
			}
			num++;
		});
		//批量操作
		$(".handle").click(function(){
			var state=$(this).attr("id");
			var a=$("input[name='checkbox']:checked");
			if(a.length==0){
            	alert("至少选中一个");
            	return;
            } 
			//获取所有已选的id存到集合
			var list=[];
			$("input[name='checkbox']:checked").each(function(i, o){
				list.push($(o).attr("id"));
            });
            //判断，state不等于null执行修改状态操作，否则执行删除操作
            if(state==0){
                if(confirm("真的要删除吗？")){
        			//循环删除
        			for(var i=0;i<a.length;i++){
        				$.get("goodslist?action=delete", {code: list[i]},function(){
        				});
        			}
        			a.parent().parent().remove();
        		}
            }else{
    			if(confirm("确定还原吗？")){
    				//循环删除
    				for(var i=0;i<a.length;i++){
    					$.get("goodslist?action=reviseIfdelete", {code: list[i],ifdelete: 1},function(){
    					});
    				}
    				a.parent().parent().remove();
    			}
            }
		});
	});
</script>
</head>
<body style="font-size: 20px;">
	<div class="top" style="padding: 20px 30px 10px; font-size: 16px;">
		<a href="#">商品</a>/
		<a href="#">商品管理</a>/
		<span>商品回收站</span>
	</div>
	<div class="middle">
		<div class="span12" style="width: 96%;">
		<a href="goodslist?action=queryByPage&curpage=1&pagesize=4&ifdelete=1&address=lgoodslist.jsp">
			<button>
				<i class="fa fa-mail-reply"></i>
				<span>返回列表</span>
			</button>
		</a>
		<a href="javascript:;" class="checkbox">
			<button>
				<i class="fa fa-check"></i>
				<span>全选</span>
			</button>
		</a>
		<a href="javascript:;">
			<button class="handle" id="0">
				<i class="fa fa-close"></i>
				<span>批量删除</span>
			</button>
		</a>
		<a href="javascript:;">
			<button class="handle" id="1">
				<i class="fa fa-recycle"></i>
				<span>批量还原</span>
			</button>
		</a>
		</div>
	</div>
	<div class="bottom">
		<div class="span12" style="width: 96%;">
			<table class="table">
			<thead>
				<tr>
					<th></th>
					<th>序号</th>
					<th>商品名称</th>
					<th>商品分类名称</th>
					<th>销售价</th>
					<th>库存</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${map.list }" var="u" varStatus="vs">
					<tr style="background-color:#${((param.curpage- 1)* param.pagesize+ vs.count)%2 eq 0?'':'cccccc'}">
						<td><input type="checkbox" name="checkbox" id="${u.g_code}"></td>
						<td>${(param.curpage - 1) * param.pagesize + vs.count}</td>
						<td>${u.g_name}</td>
						<td>${u.classify}</td>
						<td>${u.g_price}</td>
						<td>${u.g_stock}</td>
						<td>
							<a id="${u.g_code}" class="goodslist_restore" href="javascript:void(0);"><i class="fa fa-recycle"></i></a>
							<a id="${u.g_code}" class="goodslist_delete" href="javascript:void(0);"><i class="fa fa-times"></i></a>
						</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
			<div class="pager" style="float: left; margin-top: 0px;">
			<mvc:pager url="goodslist?action=queryByPage&ifdelete=0" pagesize="${param.pagesize}" count="${map.count }" curpage="${param.curpage }" />
		</div>
	</div>
	</div>
</body>
</html>